﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//------------//
using QLKTX1._0.DTO;
using QLKTX1._0.DB;
using System.Data.SqlClient;
using System.Data;
//....................
namespace QLKTX1._0.DTO
{
    class KhungGiaDienNuocDotDAO
    {
        public static List<KhungGiaDienNuocDotDTO> dsKhungGiaDienNuocDot()
        {
            List<KhungGiaDienNuocDotDTO> dsKhungGiaDienNuocDot = new List<KhungGiaDienNuocDotDTO>();

            ConnectDB con = new ConnectDB();
            DataTable dt = con.getDataTable("SELECT * FROM khungGia_DN_Dot");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                    KhungGiaDienNuocDotDTO kgdn = new KhungGiaDienNuocDotDTO();

                    DotDangKyDTO d = new DotDangKyDTO();
                    d.MaDot = dt.Rows[i]["maDot"].ToString();

                    KhungGiaDienNuocDTO k = new KhungGiaDienNuocDTO();
                    k.MaKhungGiaDienNuoc = dt.Rows[i]["maKhungGia_dienNuoc"].ToString();

                    kgdn.MaDot = d;
                    kgdn.MaKhungGiaDienNuoc = k; 
                    

                    dsKhungGiaDienNuocDot.Add(kgdn);
            }
            return dsKhungGiaDienNuocDot;

        }

        public static bool themKhungGiaDienNuocDot(KhungGiaDienNuocDotDTO k)
        {
            ConnectDB con = new ConnectDB();// dung DB

            return con.executeQuery("INSERT INTO khungGia_DN_Dot(maDot,maKhungGia_dienNuoc) VALUES('" + k.MaDot.MaDot + "','" + k.MaKhungGiaDienNuoc.MaKhungGiaDienNuoc + "')");
        }

    }
}
